package com.coocaa.ops.admin.v1.device;

import com.coocaa.ops.admin.base.annotation.Auth;
import com.coocaa.ops.admin.base.controller.MgrBaseController;
import com.coocaa.ops.admin.v1.device.converter.DeviceSaveConverter;
import com.coocaa.ops.admin.v1.device.model.GlobalDeviceInfoModel;
import com.coocaa.ops.admin.v1.device.service.IGlobalDeviceService;
import com.coocaa.ops.common.core.base.enums.AuthEnum;
import com.coocaa.ops.common.core.base.model.R;
import com.coocaa.ops.common.core.biz.device.entity.GlobalDeviceInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author tangminghong
 * @date 2019.5.18
 */
@RestController
@RequestMapping("/v1/device")
public class GlobalDeviceController extends MgrBaseController {

    @Autowired
    private IGlobalDeviceService globalDeviceService;

    @Auth(verifyAuthority = true, authorityType = AuthEnum.BROWSER)
    @RequestMapping(value = "/dataList",method = {RequestMethod.GET,RequestMethod.POST}, produces = "text/html;charset=UTF-8")
    public Object dataList(HttpServletResponse response, GlobalDeviceInfoModel model) {
        return R.ok(globalDeviceService.pageList(model));
    }

    @Auth(verifyAuthority = true, authorityType = AuthEnum.SAVE)
    @RequestMapping(value = "/save",method = {RequestMethod.GET,RequestMethod.POST}, produces = "text/html;charset=UTF-8")
    public Object save(GlobalDeviceInfoEntity entity) {
        DeviceSaveConverter.handleTrim(entity);
        globalDeviceService.save(entity);
        return R.ok();
    }
}
